package com.corner.ui.service;

import android.content.Intent;

import com.corner.R;
import com.corner.app.ConsTants;
import com.corner.utils.ApkUtil;
import com.corner.utils.NotificationUtil;
import com.corner.utils.ToastUtil;

public class UpdateDownloadService extends DownLoadService {

    private static final int MAX = 100;

    @Override
    protected void onSucess(String filePath) {
        Intent intent = ApkUtil.getInstallIntent(getApplicationContext(),
                filePath);
        // 下载成功提示安装
        NotificationUtil.showNotificationWithActivityIntent(
                getApplicationContext(), R.drawable.ic_launcher,
                R.string.download_sucess, R.string.click_update, intent, ConsTants.UPDATE_NOTIFY);
    }

    @Override
    protected void onLoading(Integer percentDone) {
        NotificationUtil.showProgressNotification(getApplicationContext(),
                R.drawable.ic_launcher, "正在下载", "已下载  " + percentDone + "%",
                MAX, percentDone, ConsTants.UPDATE_NOTIFY);
    }

    @Override
    protected void onFailed(int errorCode) {
        switch (errorCode) {
            case ERROR_FILE_DOWNLOAD:
                ToastUtil.showCustomToastInRelease(getApplicationContext(),
                        R.string.request_net_error);
                break;
            case SD_ERROR:
                ToastUtil.showCustomToastInRelease(getApplicationContext(),
                        R.string.sdcard_error);
                break;
        }
    }

}
